[EXPORTER] Convert uint64_t attribute values exceeding INT64_MAX to string per OTel spec#4090
Open
thc1006 wants to merge 1 commit into
Open
Conversation
b15a543 to
e9fc36b
Compare
There was a problem hiding this comment.
Pull request overview
Updates OTLP exporter code to align existing clang-tidy suppression comments with the clang-tidy v22 check name, and adjusts CI warning limits accordingly. This is a code health/CI maintenance change intended to keep the clang-tidy ratchet stable after the LLVM/clang-tidy 22 upgrade.
Changes:
- Renames four
NOLINTsuppressions inotlp_populate_attribute_utils.ccfrom the old alias tobugprone-narrowing-conversions. - Lowers
clang-tidyworkflow warning limits forall-options-abiv1-previewandall-options-abiv2-preview. - Adds a corresponding
CHANGELOG.mdentry.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| exporters/otlp/src/otlp_populate_attribute_utils.cc | Updates four narrowing-conversion NOLINT suppressions to match clang-tidy v22’s check name. |
| CHANGELOG.md | Adds an Unreleased entry for the code health change. |
| .github/workflows/clang-tidy.yaml | Lowers the warning limits to reflect the reduced warning count. |
e9fc36b to
cc4c581
Compare
cc4c581 to
2c3d074
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #4090 +/- ##
==========================================
+ Coverage 82.00% 82.00% +0.01%
==========================================
Files 385 385
Lines 16030 16031 +1
==========================================
+ Hits 13143 13144 +1
Misses 2887 2887
🚀 New features to boost your workflow:
|
3 tasks
thc1006
added a commit
to thc1006/opentelemetry-cpp
that referenced
this pull request
May 18, 2026
Eliminate the 29 misc-unused-alias-decls warnings flagged by clang-tidy across 27 files in examples, exporters, sdk, and tests. The most common pattern was a file-scope `namespace nostd = opentelemetry::nostd;` declaration that was never referenced via the file-scope alias path (uses of `nostd::` resolved through the surrounding OPENTELEMETRY_BEGIN_NAMESPACE namespace nesting instead). No behavior change. Removed declarations were genuinely dead per clang-tidy. Where removing an alias affected sibling-line alignment (e.g. `using M = ...` next to the removed alias), clang-format auto-collapsed the alignment. Ratchet: * abiv1-preview warning_limit lowered from 418 to 389 * abiv2-preview warning_limit lowered from 424 to 395 A 30th misc-unused-alias-decls site at exporters/otlp/src/otlp_populate_attribute_utils.cc:30 is intentionally not touched in this PR to avoid conflicting with the in-flight open-telemetry#4090. It can be cleaned up in a follow-up after open-telemetry#4090 lands. Part of open-telemetry#2053 Signed-off-by: thc1006 <84045975+thc1006@users.noreply.github.com>
thc1006
added a commit
to thc1006/opentelemetry-cpp
that referenced
this pull request
May 18, 2026
Eliminate 29 misc-unused-alias-decls warnings flagged by clang-tidy v22 across 27 files in examples, exporters, sdk, and tests. The dominant pattern was a file-scope `namespace nostd = opentelemetry::nostd;` declaration never referenced via the file-scope alias path (uses of `nostd::` resolved through OPENTELEMETRY_BEGIN_NAMESPACE namespace nesting instead). Also remove 4 unused type-alias `using M = std::map<std::string, std::string>;` declarations in storage tests, observed by Copilot review. clang-tidy does not flag these (misc-unused-alias-decls targets only namespace aliases, not type aliases), but they are genuinely dead code in the same spirit and the same files this PR already touches. No behavior change. Removed declarations were genuinely unused. clang-format auto-collapsed adjacent orphan alignment whitespace where removing a line left aligned siblings. Ratchet: * abiv1-preview warning_limit lowered from 418 to 389 * abiv2-preview warning_limit lowered from 424 to 395 A 30th misc-unused-alias-decls site at exporters/otlp/src/otlp_populate_attribute_utils.cc:30 is intentionally not touched in this PR to avoid conflicting with the in-flight open-telemetry#4090. It can be cleaned up in a trivial follow-up after open-telemetry#4090 lands. Part of open-telemetry#2053 Signed-off-by: thc1006 <84045975+thc1006@users.noreply.github.com>
thc1006
added a commit
to thc1006/opentelemetry-cpp
that referenced
this pull request
May 18, 2026
Eliminate 29 misc-unused-alias-decls warnings flagged by clang-tidy v22 across 27 files in examples, exporters, sdk, and tests. The dominant pattern was a file-scope `namespace nostd = opentelemetry::nostd;` declaration never referenced via the file-scope alias path (uses of `nostd::` resolved through OPENTELEMETRY_BEGIN_NAMESPACE namespace nesting instead). Also remove 4 unused type-alias `using M = std::map<std::string, std::string>;` declarations in storage tests, observed by Copilot review. clang-tidy does not flag these (misc-unused-alias-decls targets only namespace aliases, not type aliases), but they are genuinely dead code in the same spirit and the same files this PR already touches. No behavior change. Removed declarations were genuinely unused. clang-format auto-collapsed adjacent orphan alignment whitespace where removing a line left aligned siblings. Ratchet: * abiv1-preview warning_limit lowered from 418 to 389 * abiv2-preview warning_limit lowered from 424 to 395 A 30th misc-unused-alias-decls site at exporters/otlp/src/otlp_populate_attribute_utils.cc:30 is intentionally not touched in this PR to avoid conflicting with the in-flight open-telemetry#4090. It can be cleaned up in a trivial follow-up after open-telemetry#4090 lands. Part of open-telemetry#2053 Signed-off-by: thc1006 <84045975+thc1006@users.noreply.github.com>
thc1006
added a commit
to thc1006/opentelemetry-cpp
that referenced
this pull request
May 18, 2026
Eliminate 29 misc-unused-alias-decls warnings flagged by clang-tidy v22 across 27 files in examples, exporters, sdk, and tests. The dominant pattern was a file-scope `namespace nostd = opentelemetry::nostd;` declaration never referenced via the file-scope alias path (uses of `nostd::` resolved through OPENTELEMETRY_BEGIN_NAMESPACE namespace nesting instead). Also remove 4 unused type-alias `using M = std::map<std::string, std::string>;` declarations in storage tests, observed by Copilot review. clang-tidy does not flag these (misc-unused-alias-decls targets only namespace aliases, not type aliases), but they are genuinely dead code in the same spirit and the same files this PR already touches. Also remove 9 now-unused #include directives that IWYU flagged as a consequence of the alias removals: when an alias like `namespace http_client = opentelemetry::ext::http::client;` is removed, the include that brought the namespace into scope is no longer needed. Same logic for several `opentelemetry/common/attribute_value.h` includes that supported `namespace common = opentelemetry::common;` aliases, and `<map>` after removing the unused `using M = ...` from async_metric_storage_test.cc. No behavior change. Removed declarations were genuinely unused. clang-format auto-collapsed adjacent orphan alignment whitespace where removing a line left aligned siblings. Ratchet: * abiv1-preview warning_limit lowered from 418 to 389 * abiv2-preview warning_limit lowered from 424 to 395 A 30th misc-unused-alias-decls site at exporters/otlp/src/otlp_populate_attribute_utils.cc:30 is intentionally not touched in this PR to avoid conflicting with the in-flight open-telemetry#4090. It can be cleaned up in a trivial follow-up after open-telemetry#4090 lands. Part of open-telemetry#2053 Signed-off-by: thc1006 <84045975+thc1006@users.noreply.github.com>
2c3d074 to
785ec9a
Compare
785ec9a to
c77b2ba
Compare
…tring per OTel spec Per OpenTelemetry attribute type-mapping spec (https://opentelemetry.io/ docs/specs/otel/common/attribute-type-mapping/#integer-values), integer values outside the 64-bit signed range MUST be encoded as AnyValue's string_value using decimal representation, not wrapped to a negative int64 via narrowing. Pre-PR behavior at the four uint64_t conversion sites in otlp_populate_attribute_utils.cc was to implicitly narrow (suppressed via NOLINT). For uint64_t values exceeding INT64_MAX, this produced negative int_value on the wire — a long-standing spec violation that predates this PR. This PR fixes the violation via a file-local helper SetUint64Value that dispatches to set_int_value or set_string_value based on the value's range. All four uint64_t sites in both PopulateAnyValue overloads now follow the spec. Spec-compliance verified by three new tests in otlp_recordable_test.cc: - UINT64_MAX-equivalent value -> string_value with decimal representation - INT64_MAX boundary value -> int_value (encoding split is val > INT64_MAX) - Mixed-value array -> per-element dispatch (int + string in same array) Side effect: the four bugprone-narrowing-conversions warnings clang-tidy v22 was reporting are eliminated (the static_cast is now in a guarded branch, suppressing the diagnostic). Ratchet drops accordingly: * abiv1-preview warning_limit lowered from 389 to 385 * abiv2-preview warning_limit lowered from 395 to 391 Behavior change: existing callers relying on the wrap-to-negative behavior for uint64 > INT64_MAX will now see string_value on the wire instead of negative int_value. This was never spec-conformant; the new behavior aligns OTLP output with the protocol specification. Part of open-telemetry#2053 Signed-off-by: thc1006 <84045975+thc1006@users.noreply.github.com>
c77b2ba to
8792789
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Per OpenTelemetry attribute type-mapping spec:
Pre-PR behavior at the four
uint64_tconversion sites inexporters/otlp/src/otlp_populate_attribute_utils.ccimplicitly narrowed via// NOLINT(cppcoreguidelines-narrowing-conversions). Foruint64_tvalues exceedingINT64_MAX, this produced negativeint_valueon the wire — a long-standing spec violation that predates this PR.This PR replaces the four narrowing call sites with a file-local helper that dispatches per spec:
Both
PopulateAnyValueoverloads (forAttributeValueandOwnedAttributeValue) and both shapes (scalar and array element) route through the same helper. Spec-link comment is attached to the helper for future readers.Scope of fix (4 sites, 1 file)
otlp_populate_attribute_utils.cc:~94uint64_tscalar inAttributeValueoverloadotlp_populate_attribute_utils.cc:~187nostd::span<const uint64_t>arrayotlp_populate_attribute_utils.cc:~254uint64_tscalar inOwnedAttributeValueoverloadotlp_populate_attribute_utils.cc:~331std::vector<uint64_t>arrayOther integer conversions (
int,int64_t,unsigned int,uint32_t) always fit inint64_tand were not affected by the spec rule. No other files inexporters/orsdk/callset_int_valuewithuint64_tsource (verified via grep).Tests (new, in
otlp_recordable_test.cc)SetUint64OverflowAsStringPerSpec—INT64_MAX + 1→string_valuewith decimal representationSetUint64BoundaryAsIntPerSpec—INT64_MAX→int_value(encoding split isval > INT64_MAX)SetUint64ArrayOverflowAsStringPerSpec— mixed-value array dispatches per element (int + string in same array)Ratchet
Helper's explicit
static_castis now in a value-guarded branch, so thebugprone-narrowing-conversionsdiagnostics on these four sites are still silenced.all-options-abiv1-previewwarning_limitlowered from 389 to 385all-options-abiv2-previewwarning_limitlowered from 395 to 391Behavior change disclosure
For
uint64_tattribute values exceedingINT64_MAX(~9.2e18):int_valueon the wire (non-spec-conformant)string_value(spec-conformant)Callers relying on the wrap-to-negative behavior would see breakage. This behavior was never spec-conformant; the new behavior aligns OTLP output with the protocol specification.
Review history
Originally opened as a
[CODE HEALTH]PR to fixbugprone-narrowing-conversionswarnings viastatic_cast. @dbarker pointed out in review that the static_cast preserves the spec-violating wrap behavior and asked for spec-compliant string fallback. This PR was then upgraded in scope to the present spec fix.Test plan
clang-tidyjob passes both abiv1-preview and abiv2-preview at the new limitsFormatjob passes (verified locally viaclang-format --dry-run --Werror)int,int64_t,unsigned int,uint32_tpathsPart of #2053